home *** CD-ROM | disk | FTP | other *** search
- /* LogConvertTimestamp.c */
- /*
- * LogConvertTimestamp.c
- * Copyright © 1992-95 Apple Computer Inc. All Rights Reserved.
- *
- * This function cannot be included in the LogLibrary as it calls a MacOS "toolbox"
- * function. It can be called from a 68000 application. Note that it requires the
- * 64-bit math library.
- *
- * Edit History
- */
- #include "LogLibrary.h"
-
- void Add64(
- register const UnsignedWide *aPtr,
- register const UnsignedWide *bPtr,
- register UnsignedWide *result
- );
- void Subtract64(
- register const UnsignedWide *aPtr,
- register const UnsignedWide *bPtr,
- register UnsignedWide *result
- );
- void Multiply64(
- const UnsignedWide *multiplicand, /* Multiplier * multiplicand */
- UInt32 multiplier, /* yields result */
- UnsignedWide *resultPtr
- );
- void Divide64(
- UnsignedWide *dividendPtr, /* Dividend, becomes remainder */
- const UnsignedWide *divisorPtr, /* Divisor, unchanged */
- UnsignedWide *quotientPtr /* Quotient, result */
- );
-
- /*
- * This routine converts the event time (in AbsoluteTime units) to civil time
- * (year, month, day, hour, minute, second) with nanosecond resolution. Since the
- * relationship between civil time and
- *
- * This function calls a Mac Toolbox routine and, hence, cannot be used (legitimately)
- * by PCI device drivers.
- */
- pascal void
- LogConvertTimestamp(
- const LogEntryPtr logEntryPtr,
- DateTimeRec *eventDateTime,
- UInt32 *residualNanoseconds
- )
- {
- Nanoseconds eventNanoseconds;
- UnsignedWide eventSeconds;
- UnsignedWide temp;
- static const UnsignedWide kTenE9 = { 0, 1000000000L };
- static UInt32 gUpTimeNumerator;
- static UnsignedWide gUpTimeDenominator;
- static Nanoseconds gNanosecondsAtStart = { 0, 0};
-
- if (gNanosecondsAtStart.lo == 0 && gNanosecondsAtStart.hi == 0) {
- UnsignedWide secondsAtStart;
- AbsoluteTime absoluteTimeAtStart;
- Nanoseconds upTimeAtStart;
- Nanoseconds nanosecondsAtStart;
-
- GetDateTime(&secondsAtStart.lo);
- LogUpTime(&absoluteTimeAtStart);
- LogGetTimeBaseInfo(&gUpTimeNumerator, &gUpTimeDenominator.lo);
- /*
- * upTimeAtStart = AbsoluteToNanoseconds(UpTime())
- */
- Multiply64(&absoluteTimeAtStart, gUpTimeNumerator, &temp);
- Divide64(&temp, &gUpTimeDenominator, &upTimeAtStart);
- /*
- * Convert the system epoch to nanoseconds.
- */
- secondsAtStart.hi = 0;
- Multiply64(&secondsAtStart, kTenE9.lo, &nanosecondsAtStart);
- /*
- * Compute the offset between an UpTime value and system time of day
- */
- Subtract64(&nanosecondsAtStart, &upTimeAtStart, &gNanosecondsAtStart);
- }
- /*
- * eventNanoseconds = AbsoluteToNanoseconds(eventTime)
- * (eventTime * upTimeNumerator) / upTimeDenominator;
- */
- Multiply64(&logEntryPtr->eventTime, gUpTimeNumerator, &temp);
- Divide64(&temp, &gUpTimeDenominator, &eventNanoseconds);
- /*
- * eventNanoseconds += upTimeAtStart (giving civil time at start)
- */
- Add64(&gNanosecondsAtStart, &eventNanoseconds, &eventNanoseconds);
- /*
- * eventSeconds = eventNanoseconds /= 10e9;
- * residualNanoseconds = eventNanoseconds % 10e9;
- */
- Divide64(&eventNanoseconds, &kTenE9, &eventSeconds);
- *residualNanoseconds = eventNanoseconds.lo; /* Remainder < 10e9 */
- SecondsToDate(eventSeconds.lo, eventDateTime);
- }
-
-
-